home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 January / macformat-033.iso / mac / Shareware City / Developers / ABox.v1.8 / CPlus Files / ABUEnv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-23  |  5.6 KB  |  242 lines  |  [TEXT/MMCC]

  1. /*    
  2.     Copyright © 1991-1995 by TopSoft Inc.  All rights reserved.
  3.  
  4.     You may distribute this file under the terms of the TopSoft
  5.     Artistic License, accompanying this package.
  6.     
  7.     This file was developed by George (ty) Tempel in connection with TopSoft, Inc..
  8.     See the Modification History for more details.
  9.  
  10. Product
  11.     About Box
  12.  
  13. FILE
  14.     ABUEnv.c
  15.  
  16. NAME
  17.     ABUEnv.c, part of the ABox project source code,
  18.     responsible for mix-in handling the AboutBox environment stuff.
  19.  
  20. DESCRIPTION
  21.     This file contains defines for the about box modules.
  22.     
  23. DEVELOPED BY
  24.     George (ty) Tempel                netromancr@aol.com
  25.     All code in this file, and its associated header file was
  26.     Created by George (ty) Tempel in connection with the TopSoft, Inc.
  27.     "FilterTop" application development, except where noted.
  28.  
  29. CARETAKER - George (ty) Tempel <netromancr@aol.com>
  30.      Please consult this person for any changes or suggestions to this file.
  31.  
  32. MODIFICATION HISTORY
  33.  
  34.     dd mmm yy    -    xxx    -    patchxx: description of patch
  35.     10 June 94    -    ty    -    Initial Version Created
  36.     20-july-94    -    ty    -    initial version released
  37.     23-may-95    -    ty    -    changes for compatibility with the CodeWarrior CW6
  38.                             release and the associated Universal Headers from Apple:
  39.                             most methods that returned references now have "Ref" at
  40.                             the end of their methods names to prevent possible collisions
  41.                             with datatypes and classes of the same name (older versions
  42.                             of the compiler didn't have a problem with this).
  43.  
  44. */
  45.  
  46. /*===========================================================================*/
  47.  
  48. /*======= Segmentation directives ========*/
  49.  
  50. #ifdef USE_MANUAL_SEGMENTATION
  51. #pragma segment ty
  52. #endif
  53.  
  54. /*============ Header files ==============*/
  55.     
  56. #include     "ABUEnv.h"
  57.  
  58. /*=============== Globals ================*/
  59.  
  60. /*================ CODE ==================*/
  61.  
  62.  
  63. /*=============================== ABUEnv::ABUEnv ================================*/
  64. ABUEnv::ABUEnv(void)
  65. {
  66.     mCheckedRef = false;
  67.     mIndicator = false;
  68.     mResult = 0;
  69. }    // end ABUEnv
  70.  
  71.  
  72. /*=============================== ABUEnv::~ABUEnv ================================*/
  73. ABUEnv::~ABUEnv(void)
  74. {
  75.     // Close();
  76. }    // end ~ABUEnv
  77.  
  78.  
  79.  
  80. /*=============================== ABUEnv::CheckGestalt ================================*/
  81. OSErr
  82. ABUEnv::CheckGestalt(OSType inGestaltSelector)
  83. {
  84.     OSErr anError = noErr;
  85.     
  86.     if (this->WasntCheckedRef())
  87.     {
  88.         long theResult = 0;
  89.         this->CheckedRef() = true;
  90.         if (this->GestaltAvailable())
  91.         {
  92.             anError = ::Gestalt(inGestaltSelector, &theResult);
  93.             this->SetResult(theResult);
  94.         } else {
  95.             anError = paramErr;
  96.         }
  97.     } // end if block
  98.     return anError;
  99. }    // end CheckGestalt
  100.  
  101.  
  102.  
  103. /*=============================== ABUEnv::IsPresent ================================*/
  104. Boolean    ABUEnv::IsPresent(void)
  105. {
  106.     //    OVERRIDE THIS FUNCTION!
  107.     return false;
  108. }    // end IsPresent
  109.  
  110.  
  111.  
  112. /*=============================== ABUEnv::Feature ================================*/
  113. Boolean    ABUEnv::Feature(long mask)
  114. {
  115.     Boolean theAnswer = this->GetResult() & mask;
  116.     return theAnswer;
  117. }    // end Feature
  118.  
  119.  
  120. /*=============================== ABUEnv::Attribute ================================*/
  121. Boolean    ABUEnv::Attribute(short inBitToTest)
  122. {
  123.     return (((this->GetResult() >> inBitToTest) & 1) != 0);
  124.  
  125. }    // end Attribute
  126.  
  127.  
  128. /*=============================== ABUEnv::Initialize ================================*/
  129. OSErr    ABUEnv::Initialize(void)
  130. {
  131.     //    OVERRIDE THIS FUNCTION!
  132.     return noErr;
  133.  
  134. }    // end Initialize
  135.  
  136.  
  137.  
  138. /*=============================== ABUEnv::Close ================================*/
  139. OSErr    ABUEnv::Close(void)
  140. {
  141.     //    OVERRIDE THIS FUNCTION!
  142.     //CleanUp();
  143.     //
  144.     //    generally, you should shut down any environment stuff here
  145.     return noErr;
  146.  
  147. }    // end Close
  148.  
  149.  
  150. /*=============================== ABUEnv::CleanUp ================================*/
  151. void    ABUEnv::CleanUp(void)
  152. {
  153.     //    OVERRIDE THIS FUNCTION!
  154.     //
  155.     //    generally, you should release memory here
  156.     return;
  157.  
  158. }    // end CleanUp
  159.  
  160.  
  161.  
  162. /*=============================== ABUEnv::Begin ================================*/
  163. OSErr    ABUEnv::Begin(void)
  164. {
  165.     //    OVERRIDE THIS FUNCTION!
  166.     return noErr;
  167.  
  168. }    // end Begin
  169.  
  170.  
  171.  
  172. /*=============================== ABUEnv::End ================================*/
  173. OSErr    ABUEnv::End(void)
  174. {
  175.     //    OVERRIDE THIS FUNCTION!
  176.     return noErr;
  177.  
  178. }    // end End
  179.  
  180.  
  181.  
  182. /*=============================== Gestalt Stuff ================================*/
  183. //
  184. //  These routines, from Inside Macintosh sample code, determine whether
  185. //    the Gestalt function is available on the current system.
  186.  
  187.  
  188. /*=============================== ABUEnv::GestaltAvailable ================================*/
  189. Boolean ABUEnv::GestaltAvailable(void)
  190. {
  191.     const    gestaltTrap = 0xA1AD;
  192.     return ABUEnv::TrapAvailable(gestaltTrap);
  193. }    // end ABUEnv::GestaltAvailable
  194.  
  195.  
  196.  
  197. /*=============================== ABUEnv::TrapAvailable ================================*/
  198. Boolean    ABUEnv::TrapAvailable(short theTrap)
  199. {
  200.     TrapType     tType;
  201.     Boolean        result;
  202.     
  203.     tType = ABUEnv::GetTrapType(theTrap);
  204.     if(tType == ToolTrap)
  205.     {
  206.         theTrap = ::BitAnd(theTrap, 0x07FF);
  207.         if(theTrap >= NumToolboxTraps())
  208.             theTrap = _Unimplemented;
  209.     }
  210.     result = (::NGetTrapAddress(theTrap, tType) != 
  211.               ::NGetTrapAddress(_Unimplemented, ToolTrap));
  212.     return result;
  213. }    // end TrapAvailable
  214.  
  215.  
  216.  
  217. /*=============================== ABUEnv::NumToolboxTraps ================================*/
  218. short ABUEnv::NumToolboxTraps(void)
  219. {
  220.     if(::NGetTrapAddress(_InitGraf, ToolTrap) == ::NGetTrapAddress(0xAA6E, ToolTrap))
  221.         return 0x0200;
  222.     else
  223.         return 0x0400;
  224. }    // end NumToolboxTraps
  225.  
  226.  
  227.  
  228. /*=============================== ABUEnv::GetTrapType ================================*/
  229. TrapType ABUEnv::GetTrapType(short theTrap)
  230. {
  231.     const trapMask = 0x0800;
  232.     
  233.     if(::BitAnd(theTrap, trapMask) > 0)
  234.         return ToolTrap;
  235.     else
  236.         return OSTrap;
  237. }    // end GetTrapType
  238.  
  239.  
  240.  
  241.  
  242.